<?php
namespace app\decorate\controller;
use app\ApiRest;
use app\card\model\CardCount;
use app\decorate\model\Customer;
use app\decorate\model\Scheme;
use think\App;
use think\Request;
use app\decorate\model\AdminOfferRecord as offer_model;
use app\decorate\model\AdminHousewear;


class IndexOffer extends ApiRest{
    protected $model;
    protected $wear_model;
    public function __construct(App $app) {
        parent::__construct($app);
        $this->model      = new offer_model();
        $this->wear_model = new AdminHousewear();
    }

    /**
     * User: chenniang
     * Date: 2019-10-09 15:58
     * @return \think\Response
     * descption:报价首页
     */
    public function offerIndex(){
//        $time  = strtotime(date('Y-m-d',time()));
//        $times = $time+86400;
//        $dis[] = ['uniacid','=',$this->_uniacid];
//        $dis[] = ['create_time','between',"$time,$times"];
//        $data['count'] = $this->model->offerCount($dis);
        $site  = lbPulgSettingInfo($this->_uniacid,'decorate',['offer_img','offer_num','offer_type','offter_btn','offer_service','offer_switch']);

        $data['count'] = is_numeric($site['offer_num'])?$site['offer_num']:0;

        $data['img']   = $site['offer_img']?$site['offer_img']:"";

        $data['houseWear']     = $this->wear_model->housewearSelect(['uniacid'=>$this->_uniacid,'status'=>1]);

        $data['offer_type']    = $site['offer_type'];

        $data['offter_btn']    = $site['offter_btn'];

        $data['offer_service'] = $site['offer_service'];

        $data['offer_switch']  = $site['offer_switch'];

        return $this->success($data);
    }

    /**
     * User: chenniang
     * Date: 2019-10-23 15:38
     * @return void
     * descption:添加报价
     */
    public function offerAdd(){
        $input = $this->_input;

        $input['uniacid'] = $this->_uniacid;

        $input['user_id'] = $this->getUserId();

        $singe_price = $this->wear_model->where(['id'=>$input['hx_id']])->value('offer');

        if(!is_numeric($singe_price)){

           return $this->error('暂无该户型报价');
        }
        $input['price'] = round($singe_price*$input['m'],2);

        $res  = $this->model->offerAdd($input);

        $site = lbPulgSettingInfo($this->_uniacid,'decorate',['offer_num']);

        $num  = !empty($site['offer_num'])?$site['offer_num']+1:1;

        $res  = lbPulgSettingUpdate($this->_uniacid,'decorate','offer_num',$num);

        return $this->success($res);
    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-19 14:10
     * @功能说明:添加
     */
    public function schemeAdd(){

        $input = $this->_input;

        $scheme_model = new Scheme();

        $input['uniacid'] = $this->_uniacid;

        $input['user_id'] = $this->getUserId();

        $res = $scheme_model->dataAdd($input);

        $site = lbPulgSettingInfo($this->_uniacid,'decorate',['offer_num']);

        $num  = !empty($site['offer_num'])?$site['offer_num']+1:1;

        $res  = lbPulgSettingUpdate($this->_uniacid,'decorate','offer_num',$num);

        return $this->success($res);

    }




    /**
     * @author chenniang
     * @DataTime: 2020-11-19 11:11
     * @功能说明:客服列表
     */
    public function customerList(){

        $input = $this->_input;

        $dis = [

            'uniacid' => $this->_uniacid
        ];

        $where = [];

        if(!empty($input['name'])){

            $where[] = ['user_name','like','%'.$input['name'].'%'];

            $where[] = ['wx','like','%'.$input['name'].'%'];

            $where[] = ['mobile','like','%'.$input['name'].'%'];
        }

        $customer_model = new Customer();

        $data = $customer_model->dataList($dis,$where,10);

        return $this->success($data);

    }







}
